# """
# Description: 系统表模型
# Author: 月间
# Date: 2025-10-22 22:30:26
# LastEditTime: 2025-10-22 23:04:57
# LastEditors:
# """
#
# from advanced_alchemy.base import BigIntAuditBase
# from advanced_alchemy.base import orm_registry
# from advanced_alchemy.types import PasswordHash
# from advanced_alchemy.types.password_hash.pwdlib import PwdlibHasher
# from pwdlib.hashers.argon2 import Argon2Hasher as PwdlibArgon2Hasher
# from sqlalchemy import (
#     String,
#     Integer,
#     ForeignKey,
#     Column,
#     Table,
#     Boolean,
#     Index,
#     BigInteger,
# )
# from sqlalchemy.orm import Mapped, mapped_column, relationship
#
# sys_user_role = Table(
#     "sys_user_role",
#     orm_registry.metadata,
#     Column("user_id", BigInteger, ForeignKey("sys_user.id"), primary_key=True),
#     Column("role_id", BigInteger, ForeignKey("sys_role.id"), primary_key=True),
# )
#
# sys_user_post = Table(
#     "sys_user_post",
#     orm_registry.metadata,
#     Column("user_id", BigInteger, ForeignKey("sys_user.id"), primary_key=True),
#     Column("post_id", BigInteger, ForeignKey("sys_post.id"), primary_key=True),
# )
#
#
# class SysUser(BigIntAuditBase):
#     __tablename__ = "sys_user"
#     __table_args__ = (
#         Index("ix_sys_user_dept_id", "dept_id"),
#         Index("ix_sys_user_status", "status"),
#         Index("ix_sys_user_is_super", "is_super"),
#         Index("ix_sys_user_email", "email"),
#         Index("ix_sys_user_phone", "phone"),
#         {"comment": "用户表"},
#     )
#     username: Mapped[str] = mapped_column(
#         String(20), unique=True, nullable=False, comment="用户名"
#     )
#     nickname: Mapped[str | None] = mapped_column(String(20), comment="昵称")
#     avatar: Mapped[str | None] = mapped_column(String(255), comment="头像")
#     email: Mapped[str | None] = mapped_column(String(64), comment="邮箱")
#     phone: Mapped[str | None] = mapped_column(String(11), comment="电话")
#     password: Mapped[str] = mapped_column(
#         PasswordHash(backend=PwdlibHasher(hasher=PwdlibArgon2Hasher()))
#     )
#     status: Mapped[str] = mapped_column(
#         String(1), default="1", comment="帐号状态（1正常 2停用）"
#     )
#     is_super: Mapped[str] = mapped_column(
#         String(1), default="0", comment="帐号状态（0普通 1管理员）"
#     )
#     sex: Mapped[str] = mapped_column(String(1), comment="用户性别（0女 1男 2未知）")
#     login_ip: Mapped[str | None] = mapped_column(String(30), comment="最后登录时间")
#     remark: Mapped[str | None] = mapped_column(String(255), comment="描述")
#     # 获取部门信息 设置删除是设置为空
#     dept_id: Mapped[int | None] = mapped_column(
#         BigInteger,
#         ForeignKey("sys_dept.id", ondelete="SET NULL"),
#         comment="部门ID",
#         nullable=True,
#     )
#     # 获取角色信息
#     roles: Mapped[set["SysRole"]] = relationship("SysRole", secondary=sys_user_role)
#     # 岗位信息
#     posts: Mapped[set["SysPost"]] = relationship("SysPost", secondary=sys_user_post)
#     # 菜单信息
#     dept: Mapped["SysDept"] = relationship("SysDept")
#
#
# sys_role_menu = Table(
#     "sys_role_menu",
#     orm_registry.metadata,
#     Column("role_id", BigInteger, ForeignKey("sys_role.id"), primary_key=True),
#     Column("menu_id", BigInteger, ForeignKey("sys_menu.id"), primary_key=True),
# )
#
# sys_role_dept = Table(
#     "sys_role_dept",
#     orm_registry.metadata,
#     Column("role_id", BigInteger, ForeignKey("sys_role.id"), primary_key=True),
#     Column("dept_id", BigInteger, ForeignKey("sys_dept.id"), primary_key=True),
# )
#
#
# class SysRole(BigIntAuditBase):
#     __tablename__ = "sys_role"
#     __table_args__ = (
#         Index("ix_sys_role_role_key", "role_key"),
#         Index("ix_sys_role_status", "status"),
#         {"comment": "角色表"},
#     )
#     role_name: Mapped[str] = mapped_column(
#         String(30), nullable=False, comment="角色名称"
#     )
#     role_key: Mapped[str] = mapped_column(
#         String(100), nullable=False, comment="角色权限字符串"
#     )
#     # 首页key
#     home_key: Mapped[str] = mapped_column(
#         String(100), default="home", comment="首页key"
#     )
#     role_sort: Mapped[int] = mapped_column(Integer, nullable=False, comment="显示顺序")
#     data_scope: Mapped[int] = mapped_column(
#         Integer,
#         default=0,
#         comment="数据范围（0 仅本人数据权限 1 本部门数据权限 2 本部门及以下数据权限 3 自定义数据权限 4 全部数据权限）",
#     )
#     menu_check_strictly: Mapped[int] = mapped_column(
#         Integer, default=1, comment="菜单树选择项是否关联显示"
#     )
#     dept_check_strictly: Mapped[int] = mapped_column(
#         Integer, default=1, comment="部门树选择项是否关联显示"
#     )
#     status: Mapped[str] = mapped_column(
#         String(1), nullable=False, comment="角色状态（1正常 2停用）"
#     )
#     remark: Mapped[str | None] = mapped_column(String(500), comment="备注")
#     # 菜单关系
#     menus: Mapped[set["SysMenu"]] = relationship(secondary=sys_role_menu)
#     # 部门关系
#     depts: Mapped[set["SysDept"]] = relationship(secondary=sys_role_dept)
#
#
# class SysPost(BigIntAuditBase):
#     __tablename__ = "sys_post"
#     __table_args__ = (
#         Index("ix_sys_post_post_code", "post_code"),
#         Index("ix_sys_post_status", "status"),
#         {"comment": "岗位表"},
#     )
#     post_code: Mapped[str] = mapped_column(String(20), comment="岗位编码")
#     post_name: Mapped[str] = mapped_column(String(20), comment="岗位名称")
#     remark: Mapped[str | None] = mapped_column(String(500), comment="备注")
#     post_sort: Mapped[int] = mapped_column(Integer, nullable=False, comment="显示顺序")
#     status: Mapped[str] = mapped_column(
#         String(1), nullable=False, default="0", comment="状态（1正常 2停用）"
#     )
#
#
# class SysDept(BigIntAuditBase):
#     __tablename__ = "sys_dept"
#     __table_args__ = (
#         Index("ix_sys_dept_parent_id", "parent_id"),
#         Index("ix_sys_dept_status", "status"),
#         {"comment": "部门表"},
#     )
#
#     dept_name: Mapped[str] = mapped_column(
#         String(20), nullable=False, comment="部门名称"
#     )
#     parent_id: Mapped[int | None] = mapped_column(
#         BigInteger,
#         ForeignKey("sys_dept.id", ondelete="SET NULL"),
#         nullable=True,
#         comment="父级ID",
#     )
#     ancestors: Mapped[str] = mapped_column(String(255), comment="祖级列表")
#     status: Mapped[str] = mapped_column(
#         String(1), default="1", comment="帐号状态（1正常 2停用）"
#     )
#     leader: Mapped[str | None] = mapped_column(String(20), comment="部门领导")
#     phone: Mapped[str | None] = mapped_column(String(11), comment="电话")
#     order_num: Mapped[int] = mapped_column(Integer, comment="排序")
#     remark: Mapped[str | None] = mapped_column(String(500), comment="备注")
#
#
# class SysMenu(BigIntAuditBase):
#     __tablename__ = "sys_menu"
#     __table_args__ = (
#         Index("ix_sys_menu_status", "status"),
#         Index("ix_sys_menu_parent_id", "parent_id"),
#         Index("ix_sys_menu_menu_type", "menu_type"),
#         Index("ix_sys_menu_permissions", "permissions"),
#         Index("ix_sys_menu_route_name", "route_name"),
#         Index("ix_sys_menu_route_path", "route_path"),
#         {"comment": "菜单表"},
#     )
#
#     parent_id: Mapped[int | None] = mapped_column(
#         BigInteger,
#         ForeignKey("sys_menu.id", ondelete="SET NULL"),
#         nullable=True,
#         comment="父菜单ID",
#     )
#     menu_type: Mapped[str] = mapped_column(
#         String(1), comment="菜单类型; 1:目录，2:菜单，3: 按钮"
#     )
#     permissions: Mapped[str | None] = mapped_column(
#         String(100), nullable=True, default=None, comment="权限标识"
#     )
#     menu_name: Mapped[str] = mapped_column(String(64), comment="菜单名称")
#     route_name: Mapped[str | None] = mapped_column(String(64), comment="路由名称")
#     route_path: Mapped[str | None] = mapped_column(String(64), comment="路由路径")
#     component: Mapped[str | None] = mapped_column(String(64), comment="组件路径")
#     order: Mapped[int] = mapped_column(Integer, comment="排序")
#     i18n_key: Mapped[str | None] = mapped_column(String(64), comment="国际化Key")
#     icon: Mapped[str | None] = mapped_column(String(64), comment="图标")
#     icon_type: Mapped[str | None] = mapped_column(String(64), comment="图标类型")
#
#     path_param: Mapped[str | None] = mapped_column(String(200), comment="路径参数")
#     route_param: Mapped[str | None] = mapped_column(
#         String(200), comment="路由参数, List[dict]"
#     )
#     href: Mapped[str | None] = mapped_column(String(200), comment="外链")
#     multiple_tab: Mapped[bool | None] = mapped_column(
#         Boolean, default=False, comment="是否支持多页签"
#     )
#     keep_alive: Mapped[bool] = mapped_column(Boolean, default=False, comment="是否缓存")
#     hide_in_menu: Mapped[bool] = mapped_column(
#         Boolean, default=False, comment="是否在菜单隐藏"
#     )
#     active_menu: Mapped[str | None] = mapped_column(
#         String(100), comment="隐藏的路由需要激活的菜单"
#     )
#     fixed_index_in_tab: Mapped[int | None] = mapped_column(
#         Integer, comment="固定在页签的序号"
#     )
#     redirect: Mapped[str | None] = mapped_column(String(200), comment="重定向路径")
#     props: Mapped[bool | None] = mapped_column(
#         Boolean, default=False, comment="是否为首路由"
#     )
#     constant: Mapped[bool | None] = mapped_column(
#         Boolean, default=False, comment="是否为公共路由"
#     )
#     status: Mapped[str] = mapped_column(
#         String(1), default="1", comment="菜单状态1正常，2禁用"
#     )
